

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>cup.jenkinslib.internal.job &mdash; cup 1.7.0 documentation</title>
  

  
  
  
  

  

  
  
    

  

  <link rel="stylesheet" href="../../../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../../../genindex/" />
    <link rel="search" title="Search" href="../../../../../search/" /> 

  
  <script src="../../../../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../../../../" class="icon icon-home"> cup
          

          
          </a>

          
            
            
              <div class="version">
                1.7
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../../cup/">cup package</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../../../">cup</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../../../">Docs</a> &raquo;</li>
        
          <li><a href="../../../../">Module code</a> &raquo;</li>
        
      <li>cup.jenkinslib.internal.job</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for cup.jenkinslib.internal.job</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: utf-8 -*</span>
<span class="c1"># Copyright: [CUP] - See LICENSE for details.</span>
<span class="c1"># Authors: liushuxian(liushuxian)</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module provides Job object.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">logging</span>

<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">xml.etree.cElementTree</span> <span class="k">as</span> <span class="nn">ET</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">xml.etree.ElementTree</span> <span class="k">as</span> <span class="nn">ET</span>

<span class="kn">import</span> <span class="nn">cup</span>
<span class="kn">from</span> <span class="nn">cup.jenkinslib.internal</span> <span class="k">import</span> <span class="n">base</span>
<span class="kn">from</span> <span class="nn">cup.jenkinslib.internal</span> <span class="k">import</span> <span class="n">exception</span>
<span class="kn">from</span> <span class="nn">cup.jenkinslib.internal</span> <span class="k">import</span> <span class="n">queue</span>


<span class="k">class</span> <span class="nc">Job</span><span class="p">(</span><span class="n">base</span><span class="o">.</span><span class="n">JenkinsBase</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Represents a job.&quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">jenkins</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;initialize Job object.</span>

<span class="sd">        Args:</span>
<span class="sd">            url: url of job.</span>
<span class="sd">            name: name of job.</span>
<span class="sd">            job: Job object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span> <span class="o">=</span> <span class="n">jenkins</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">Job</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">static</span><span class="o">=</span><span class="n">jenkins</span><span class="o">.</span><span class="n">is_static</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_config</span> <span class="o">=</span> <span class="kc">None</span>         <span class="c1"># element tree object of config</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_config_text</span> <span class="o">=</span> <span class="kc">None</span>    <span class="c1"># text of config</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_promotions</span> <span class="o">=</span> <span class="kc">None</span>     <span class="c1"># promotions object</span>

    <span class="k">def</span> <span class="nf">get_jenkins_obj</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get object of current jenkins.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span>

    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>

    <span class="k">def</span> <span class="nf">invoke</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">block</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">build_params</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cause</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">files</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">delay</span><span class="o">=</span><span class="mi">15</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;trigger a new build.</span>

<span class="sd">        Args:</span>
<span class="sd">            block: block until the new build stopped.</span>
<span class="sd">            build_params: trigger new build with params.</span>
<span class="sd">            cause: set cause info.</span>
<span class="sd">            files: send build params in files.</span>
<span class="sd">            delay: if `block` is True, check status every `delay` seconds.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">block</span><span class="p">,</span> <span class="nb">bool</span><span class="p">):</span>
            <span class="k">raise</span> <span class="n">exception</span><span class="o">.</span><span class="n">ParamTypeError</span><span class="p">(</span><span class="s2">&quot;block&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">build_params</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_params</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">exception</span><span class="o">.</span><span class="n">BadParams</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> does not support parameters&quot;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>

        <span class="n">params</span> <span class="o">=</span> <span class="p">{}</span>  <span class="c1"># Via Get string</span>

        <span class="c1"># Either copy the params dict or make a new one.</span>
        <span class="n">build_params</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">build_params</span><span class="o">.</span><span class="n">items</span><span class="p">())</span> <span class="k">if</span> <span class="n">build_params</span> <span class="k">else</span> <span class="p">{}</span>

        <span class="k">if</span> <span class="n">cause</span><span class="p">:</span>
            <span class="n">build_params</span><span class="p">[</span><span class="s1">&#39;cause&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">cause</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_build_trigger_url</span><span class="p">(</span><span class="n">files</span><span class="p">)</span>

        <span class="c1"># Build require params as form fields and as Json.</span>
        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;json&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">mk_json_from_build_parameters</span><span class="p">(</span><span class="n">build_params</span><span class="p">,</span> <span class="n">files</span><span class="p">)}</span>
        <span class="n">data</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">build_params</span><span class="p">)</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="o">.</span><span class="n">requester</span><span class="o">.</span><span class="n">post_and_confirm_status</span><span class="p">(</span>
            <span class="n">url</span><span class="p">,</span>
            <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span>
            <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">,</span>
            <span class="n">files</span><span class="o">=</span><span class="n">files</span><span class="p">,</span>
            <span class="n">valid</span><span class="o">=</span><span class="p">[</span><span class="mi">200</span><span class="p">,</span> <span class="mi">201</span><span class="p">,</span> <span class="mi">303</span><span class="p">],</span>
            <span class="n">allow_redirects</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

        <span class="n">redirect_url</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">&#39;location&#39;</span><span class="p">]</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">redirect_url</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">/queue/item&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="o">.</span><span class="n">url</span><span class="p">):</span>
            <span class="k">raise</span> <span class="n">exception</span><span class="o">.</span><span class="n">BadValue</span><span class="p">(</span><span class="s2">&quot;Not a Queue URL: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">redirect_url</span><span class="p">)</span>

        <span class="n">qi</span> <span class="o">=</span> <span class="n">queue</span><span class="o">.</span><span class="n">QueueItem</span><span class="p">(</span><span class="n">redirect_url</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">block</span><span class="p">:</span>
            <span class="n">qi</span><span class="o">.</span><span class="n">block_until_complete</span><span class="p">(</span><span class="n">delay</span><span class="o">=</span><span class="n">delay</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">qi</span>

    <span class="c1"># set build same as invoke</span>
    <span class="n">build</span> <span class="o">=</span> <span class="n">invoke</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_enabled</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;check if job is enabled.&quot;&quot;&quot;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">poll</span><span class="p">(</span><span class="n">tree</span><span class="o">=</span><span class="s1">&#39;color&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;color&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="o">!=</span> <span class="s1">&#39;disabled&#39;</span>

    <span class="k">def</span> <span class="nf">disable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;disable job.&quot;&quot;&quot;</span>
        <span class="n">url</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">/disable&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">url</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="o">.</span><span class="n">requester</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">enable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;enable job.&quot;&quot;&quot;</span>
        <span class="n">url</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">/enable&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">url</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="o">.</span><span class="n">requester</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_queued</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;check job is queued or not.&quot;&quot;&quot;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">poll</span><span class="p">(</span><span class="n">tree</span><span class="o">=</span><span class="s1">&#39;inQueue&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;inQueue&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_running</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;check job is running or not.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">last_build</span><span class="o">.</span><span class="n">is_running</span>
        <span class="k">except</span> <span class="n">NoBuildData</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;no build info for </span><span class="si">%s</span><span class="s2">, assume not running&quot;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
        <span class="k">return</span> <span class="kc">False</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_queued_or_running</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;check job is queued/running or not.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_queued</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_running</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">upstream_job_names</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get list of upstream job names.&quot;&quot;&quot;</span>
        <span class="n">upstream_jobs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="p">[</span><span class="s1">&#39;upstreamProjects&#39;</span><span class="p">]:</span>
                <span class="n">upstream_jobs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">j</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">])</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>
        <span class="k">return</span> <span class="n">upstream_jobs</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">upstream_jobs</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get list of upstream job objects.&quot;&quot;&quot;</span>
        <span class="n">upstream_jobs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="p">[</span><span class="s1">&#39;upstreamProjects&#39;</span><span class="p">]:</span>
                <span class="n">upstream_jobs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="o">.</span><span class="n">get_job</span><span class="p">(</span><span class="n">j</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">]))</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>
        <span class="k">return</span> <span class="n">upstream_jobs</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">downstream_job_names</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get list of downstream job names.&quot;&quot;&quot;</span>
        <span class="n">downstream_jobs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="p">[</span><span class="s1">&#39;downstreamProjects&#39;</span><span class="p">]:</span>
                <span class="n">downstream_jobs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">j</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">])</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>
        <span class="k">return</span> <span class="n">downstream_jobs</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">downstream_jobs</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get list of downstream job objects.&quot;&quot;&quot;</span>
        <span class="n">downstream_jobs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="p">[</span><span class="s1">&#39;downstreamProjects&#39;</span><span class="p">]:</span>
                <span class="n">downstream_jobs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="o">.</span><span class="n">get_job</span><span class="p">(</span><span class="n">j</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">]))</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>
        <span class="k">return</span> <span class="n">downstream_jobs</span>

    <span class="k">def</span> <span class="nf">_get_build_number</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">build_type</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get special build number by type.</span>

<span class="sd">        Args:</span>
<span class="sd">            build_type:</span>
<span class="sd">                firstBuild</span>
<span class="sd">                lastBuild</span>
<span class="sd">                lastStableBuild</span>
<span class="sd">                lastSuccessfulBuild</span>
<span class="sd">                lastCompletedBuild</span>
<span class="sd">                lastFailedBuild</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">poll</span><span class="p">(</span><span class="n">tree</span><span class="o">=</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">[number]&#39;</span> <span class="o">%</span> <span class="n">build_type</span><span class="p">)</span>

        <span class="n">info</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">build_type</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">info</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">exception</span><span class="o">.</span><span class="n">NoBuildData</span><span class="p">(</span><span class="n">build_type</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">info</span><span class="p">[</span><span class="s2">&quot;number&quot;</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">first_build_number</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get number of first build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_build_number</span><span class="p">(</span><span class="s2">&quot;firstBuild&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">last_build_number</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get number of last build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_build_number</span><span class="p">(</span><span class="s2">&quot;lastBuild&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">last_stable_build_number</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get number of last stable build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_build_number</span><span class="p">(</span><span class="s2">&quot;lastStableBuild&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">last_successful_build_number</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get number of last successful build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_build_number</span><span class="p">(</span><span class="s2">&quot;lastSuccessfulBuild&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">last_completed_build_number</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get number of last completed build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_build_number</span><span class="p">(</span><span class="s2">&quot;lastCompletedBuild&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">last_failed_build_number</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get number of last failed build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_build_number</span><span class="p">(</span><span class="s2">&quot;lastFailedBuild&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">next_build_number</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get number of next build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;nextBuildNumber&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">builds</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get container of all builds.&quot;&quot;&quot;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">poll</span><span class="p">(</span><span class="n">tree</span><span class="o">=</span><span class="s1">&#39;builds[number,url]&#39;</span><span class="p">)</span>
        <span class="n">builds</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;builds&quot;</span><span class="p">,</span> <span class="p">[])</span>
        <span class="k">return</span> <span class="nb">dict</span><span class="p">((</span><span class="n">build</span><span class="p">[</span><span class="s2">&quot;number&quot;</span><span class="p">],</span> <span class="n">build</span><span class="p">[</span><span class="s2">&quot;url&quot;</span><span class="p">])</span> <span class="k">for</span> <span class="n">build</span> <span class="ow">in</span> <span class="n">builds</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">get_build</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">build_number</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get build by number.</span>

<span class="sd">        Also support special build:</span>
<span class="sd">                firstBuild</span>
<span class="sd">                lastBuild</span>
<span class="sd">                lastStableBuild</span>
<span class="sd">                lastSuccessfulBuild</span>
<span class="sd">                lastCompletedBuild</span>
<span class="sd">                lastFailedBuild</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># if build_number is not int, maybe it is like &quot;lastStableBuild&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">build_number</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
            <span class="n">build_number</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_build_number</span><span class="p">(</span><span class="n">build_number</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">builds</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">build_number</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">url</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">build_number</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">next_build_number</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">exception</span><span class="o">.</span><span class="n">NoBuildData</span><span class="p">(</span><span class="n">build_number</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">exception</span><span class="o">.</span><span class="n">DeletedBuild</span><span class="p">(</span><span class="n">build_number</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="o">.</span><span class="n">Build</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">build_number</span><span class="p">,</span> <span class="n">job</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="n">depth</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">first_build</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get first build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_build</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">first_build_number</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">last_build</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get last build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_build</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">last_build_number</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">last_stable_build</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get last stable build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_build</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">last_stable_build_number</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">last_successful_build</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get last successful build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_build</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">last_successful_build_number</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">last_completed_build</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get last completed build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_build</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">last_completed_build_number</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">last_failed_build</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get last failed build.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_build</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">last_failed_build_number</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get build by number.</span>

<span class="sd">        Suppport promotions.</span>

<span class="sd">        Also support special build:</span>
<span class="sd">                firstBuild</span>
<span class="sd">                lastBuild</span>
<span class="sd">                lastStableBuild</span>
<span class="sd">                lastSuccessfulBuild</span>
<span class="sd">                lastCompletedBuild</span>
<span class="sd">                lastFailedBuild</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="s2">&quot;promotions&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">promotions</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_build</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">build_number</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;build exists or not.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">build_number</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">builds</span>

    <span class="k">def</span> <span class="nf">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;iterator for builds.&quot;&quot;&quot;</span>
        <span class="n">builds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">builds</span>
        <span class="n">numbers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">builds</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
        <span class="n">numbers</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
        <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="o">.</span><span class="n">Build</span><span class="p">(</span><span class="n">builds</span><span class="p">[</span><span class="n">number</span><span class="p">],</span> <span class="n">number</span><span class="p">,</span> <span class="n">job</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span> <span class="k">for</span> <span class="n">number</span> <span class="ow">in</span> <span class="n">numbers</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">promotions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get promotions of job.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_promotions</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_promotions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="o">.</span><span class="n">Promotions</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_promotions</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">config_text</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get config.xml text of job.</span>

<span class="sd">        Returns:</span>
<span class="sd">            config.xml text in Unicode type.</span>
<span class="sd">            You can encode it in &#39;utf-8&#39; or &#39;gb18030&#39;.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_config_text</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_config_text</span>

        <span class="n">url</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">/config.xml&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">url</span>
        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="o">.</span><span class="n">requester</span><span class="o">.</span><span class="n">get_and_confirm_status</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_config_text</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">text</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_config_text</span>

    <span class="nd">@config_text</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">config_text</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;update config by text.</span>

<span class="sd">        Args:</span>
<span class="sd">            config: str format of config.xml text.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">config</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">config</span><span class="p">)</span>
        <span class="n">url</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">/config.xml&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">url</span>
        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">jenkins</span><span class="o">.</span><span class="n">requester</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="p">{},</span> <span class="n">data</span><span class="o">=</span><span class="n">config</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_config_text</span> <span class="o">=</span> <span class="n">config</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_config</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_config_text</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">config</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get config element tree object of job.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_config</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_config</span>

        <span class="k">return</span> <span class="n">ET</span><span class="o">.</span><span class="n">fromstring</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">config_text</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">))</span>

    <span class="nd">@config</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;update config by element tree object.</span>

<span class="sd">        Args:</span>
<span class="sd">            config: element tree object of config.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">config_text</span> <span class="o">=</span> <span class="n">ET</span><span class="o">.</span><span class="n">tostring</span><span class="p">(</span><span class="n">config</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">description</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get description of job.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="p">[</span><span class="s2">&quot;description&quot;</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">has_params</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;check build has params or not.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">any</span><span class="p">(</span><span class="s2">&quot;parameterDefinitions&quot;</span> <span class="ow">in</span> <span class="n">a</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="p">[</span><span class="s2">&quot;actions&quot;</span><span class="p">]</span> <span class="k">if</span> <span class="n">a</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">get_build_trigger_url</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">files</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get trigger url of job.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">files</span> <span class="ow">or</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_params</span><span class="p">:</span>
            <span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">/build&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">url</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">/buildWithParameters&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">url</span>

    <span class="k">def</span> <span class="nf">get_delete_url</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get delete url of job.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">/doDelete&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">url</span>

    <span class="k">def</span> <span class="nf">get_rename_url</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get rename url of job.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">/doRename&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">url</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">_mk_json_from_build_parameters</span><span class="p">(</span><span class="n">build_params</span><span class="p">,</span> <span class="n">file_params</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;make build parameters to json format.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">build_params</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="k">raise</span> <span class="n">exception</span><span class="o">.</span><span class="n">ParamTypeError</span><span class="p">(</span><span class="s2">&quot;Build parameters must be a dict&quot;</span><span class="p">)</span>

        <span class="n">build_p</span> <span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="n">k</span><span class="p">,</span> <span class="s1">&#39;value&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">v</span><span class="p">)}</span>
                   <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">build_params</span><span class="o">.</span><span class="n">items</span><span class="p">())]</span>
        <span class="n">out</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;parameter&#39;</span><span class="p">:</span> <span class="n">build_p</span><span class="p">}</span>
        <span class="k">if</span> <span class="n">file_params</span><span class="p">:</span>
            <span class="n">file_p</span> <span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="n">k</span><span class="p">,</span> <span class="s1">&#39;file&#39;</span><span class="p">:</span> <span class="n">k</span><span class="p">}</span>
                      <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">file_params</span><span class="o">.</span><span class="n">keys</span><span class="p">()]</span>
            <span class="n">out</span><span class="p">[</span><span class="s1">&#39;parameter&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">file_p</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">out</span><span class="p">[</span><span class="s1">&#39;parameter&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">out</span><span class="p">[</span><span class="s1">&#39;parameter&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">out</span><span class="p">[</span><span class="s1">&#39;parameter&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">out</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">mk_json_from_build_parameters</span><span class="p">(</span><span class="n">build_params</span><span class="p">,</span> <span class="n">file_params</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;make build parameters to json format.&quot;&quot;&quot;</span>
        <span class="n">json_structure</span> <span class="o">=</span> <span class="n">Job</span><span class="o">.</span><span class="n">_mk_json_from_build_parameters</span><span class="p">(</span>
            <span class="n">build_params</span><span class="p">,</span>
            <span class="n">file_params</span><span class="p">)</span>
        <span class="n">json_structure</span><span class="p">[</span><span class="s1">&#39;statusCode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;303&quot;</span>
        <span class="n">json_structure</span><span class="p">[</span><span class="s1">&#39;redirectTo&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;.&quot;</span>
        <span class="k">return</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">json_structure</span><span class="p">)</span>

</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, CUP-DEV.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../../../../',
            VERSION:'1.7.0',
            LANGUAGE:'en',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../../../../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../../../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../../../../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  <script type="text/javascript" src="../../../../../_static/js/theme.js"></script>

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>